package com.liuzhengting.utils.DETION;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class Base64Util {
	
	private static Base64.Decoder decoder = Base64.getDecoder();
	private static Base64.Encoder encoder = Base64.getEncoder();
	
	/**
	 * Java8提供Base64
	 * 加密
	 * @param str
	 * @return
	 */
	public static String Base64Encryption(String str) {
		try {
			String Encryption = encoder.encodeToString(str.getBytes("UTF-8"));
			System.out.println("加密成功返回加密后文本"+Encryption);
			return Encryption;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * Java8提供Base64
	 * 解密
	 * @param str
	 * @return
	 */
	public static String Base64Decryption(String str) {
		try {
			String Decryption = new String(decoder.decode(str), "UTF-8");
			System.out.println("解密成功返回解密后文本"+Decryption);
			return Decryption;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
}
